package com.taobao.txc.resourcemanager.mt;

import com.taobao.txc.a.b.g;
import com.taobao.txc.common.LoggerInit;
import com.taobao.txc.common.LoggerWrap;
import com.taobao.txc.common.TxcContext;
import com.taobao.txc.common.a;
import com.taobao.txc.common.config.o;
import java.lang.reflect.Method;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

public class MtBranchInterceptor
  implements MethodInterceptor
{
  private com.taobao.txc.resourcemanager.b a = MtResourceManager.getTxcResourceManager();
  private static final LoggerWrap b = LoggerInit.logger;
  private Boolean c = null;
  
  public Object invoke(MethodInvocation paramMethodInvocation)
  {
    if (!paramMethodInvocation.getMethod().isAnnotationPresent(MtBranch.class))
    {
      localObject1 = TxcContext.suspendTxcTransaction();
      localObject2 = null;
      try
      {
        localObject2 = paramMethodInvocation.proceed();
      }
      finally
      {
        TxcContext.resumeTxcTransaction((String)localObject1);
      }
      return localObject2;
    }
    Object localObject1 = null;
    Object localObject2 = TxcContext.getCurrentXid();
    long l1 = 0L;
    long l2 = System.currentTimeMillis();
    try
    {
      localObject1 = (MtBranch)paramMethodInvocation.getMethod().getAnnotation(MtBranch.class);
      l1 = this.a.a(((MtBranch)localObject1).name(), null, a.b);
      paramMethodInvocation.getArguments()[0] = localObject2;
      paramMethodInvocation.getArguments()[1] = new Long(l1);
      com.taobao.txc.resourcemanager.mt.a.b.a().set((String)localObject2 + ":" + l1);
    }
    finally
    {
      b.info(String.format("[%s] [%d:%d] regist mt branch, cost %d ms.", new Object[] { ((MtBranch)localObject1).name(), Long.valueOf(TxcContext.d()), Long.valueOf(l1), Long.valueOf(System.currentTimeMillis() - l2) }));
    }
    String str1 = TxcContext.suspendTxcTransaction();
    Object localObject5 = null;
    try
    {
      localObject5 = paramMethodInvocation.proceed();
    }
    catch (Exception localException1)
    {
      String str3 = TxcContext.i();
      TxcContext.resumeTxcTransaction(str1);
      try
      {
        if (this.c == null) {
          this.c = new Boolean(o.a().f(g.f()));
        }
        this.a.a(l1, this.c.booleanValue(), ((MtBranch)localObject1).name(), str3);
        b.info(String.format("[%s] [%d:%d] reportStatus %b, cost %d ms.", new Object[] { ((MtBranch)localObject1).name(), Long.valueOf(TxcContext.d()), Long.valueOf(l1), Boolean.valueOf(this.c.booleanValue()), Long.valueOf(System.currentTimeMillis() - l2) }));
      }
      catch (Exception localException3)
      {
        if (str3 != null)
        {
          b.info(String.format("[%s] [%d:%d] try failed, and report status failed, cost %d ms.", new Object[] { ((MtBranch)localObject1).name(), Long.valueOf(TxcContext.d()), Long.valueOf(l1), Long.valueOf(System.currentTimeMillis() - l2) }));
          str1 = TxcContext.suspendTxcTransaction();
          this.a.a((String)localObject2, l1, ((MtBranch)localObject1).name(), str3, (byte)a.b.a());
          TxcContext.resumeTxcTransaction(str1);
        }
      }
      throw localException1;
    }
    String str2 = TxcContext.i();
    TxcContext.resumeTxcTransaction(str1);
    try
    {
      this.a.a(l1, true, ((MtBranch)localObject1).name(), str2);
      b.info(String.format("[%s] [%d:%d] reportStatus true, cost %d ms.", new Object[] { ((MtBranch)localObject1).name(), Long.valueOf(TxcContext.d()), Long.valueOf(l1), Long.valueOf(System.currentTimeMillis() - l2) }));
    }
    catch (Exception localException2)
    {
      if (str2 != null)
      {
        b.info(String.format("[%s] [%d:%d] try success, but report status failed, cost %d ms.", new Object[] { ((MtBranch)localObject1).name(), Long.valueOf(TxcContext.d()), Long.valueOf(l1), Long.valueOf(System.currentTimeMillis() - l2) }));
        str1 = TxcContext.suspendTxcTransaction();
        this.a.a((String)localObject2, l1, ((MtBranch)localObject1).name(), str2, (byte)a.b.a());
        TxcContext.resumeTxcTransaction(str1);
      }
      throw localException2;
    }
    return localObject5;
  }
}


/* Location:           C:\Users\ibm\Downloads\txc-yun-sample (1)\txc-yun-sample\lib\txc-client-2.0.72.jar
 * Qualified Name:     com.taobao.txc.resourcemanager.mt.MtBranchInterceptor
 * JD-Core Version:    0.7.0.1
 */